<?php
  require("utilities.php");
  if($_GET['delete']){
    $sid = (int)$_GET['delete'];
    mysql_query("Delete From student where SID = {$sid}");
    header("Location: database.php");
    exit;
  }
  if($_POST){
    $info=array();
    $info['Fname'] = mysql_real_escape_string($_POST['Fname']);
    $info['Lname'] = mysql_real_escape_string($_POST['Lname']);
    $info['Bday']  = mysql_real_escape_string($_POST['Bday']);
    mysql_query("INSERT into student (Fname,Lname,Bday) VALUES ('{$info['Fname']}','{$info['Lname']}','{$info['Bday']}');");
    header("Location: database.php");
    exit;
  }
?>
<html>
  <head>
    <title>Trevor Lee Dilley</title>
    <link rel="stylesheet" href="test.css" type="text/css" />
  </head>
  <body>
    <table border="0" height="600" width="770">
      <tr> 
        <td height="100" colspan="2" class="header">
 <?php
    echo "Hello, Zygomatic World!";
 ?>
        </td>
      </tr>
      <tr>
        <td width="120" valign="top" class="links">
          Lets put some links here
        </td>
        <td width="400" valign="top" class="body" >
        <table cellpadding="4" cellspacing="0" width="100%">
          <tr>
            <th> First Name </th>
            <th> Last Name </th>
            <th> BirthDay </th>
            <th> Delete? </th>
          </tr>
          <?php
            $query = mysql_query("SELECT * FROM student WHERE 1 ORDER BY Lname asc, Fname asc");
            $count = 0;
            while($row = mysql_fetch_assoc($query)){
              $style = ($count%2 == 0) ? 'row1' : 'row2';
              echo "<tr class=\"{$style}\">\n";
              echo "<td>{$row['Fname']}</td>\n";
              echo "<td>{$row['Lname']}</td>\n";
              echo "<td>{$row['Bday']}</td>\n";
              echo "<td><a href= \"?delete={$row[SID]}\">Delete? </a></td>";
              echo "</tr>\n";
              $count++;
            }
          ?> 
        </table>
        <form name="form1" method="post" action="database.php">
        <table cellpadding="4" cellspacing="0" width="100%">
          <tr>
            <th> First Name </th>
            <th> Last Name </th>
            <th> BirthDay </th> 
          </tr>
          <tr>
            <td><input type="text" name="Fname" size="10" /></td>
            <td><input type="text" name="Lname" size="10" /></td>
            <td><input type="text" name="Bday" size="10" /></td>
          </tr>
        </table>
        <p align="center"><input type="submit" value="Insert"/></p>
        </form>
        </td>
      </tr>
    </table>
  </body>
</html>
